<template>
    <div>
        <button class="content" @click="click">点击跳转vueRouter</button>
    </div>
</template>

<script lang="ts" setup>
import { useRouter } from 'vue-router';
import { onUnmounted } from 'vue';

const router = useRouter();
const click = () => {
    console.log('点击了');
    router.push({ name: 'keepAlive' });
};

// 修复Web Worker初始化
const worker = new Worker(new URL('@/workers/test.ts', import.meta.url), {
    type: 'module', // 确保使用模块类型
});

// 监听Worker消息
worker.onmessage = (event) => {
    console.log('从Worker收到的结果:', event.data);
};

// 发送数据到Worker
worker.postMessage(5);

// 组件卸载时终止Worker
onUnmounted(() => {
    worker.terminate();
    console.log('Worker已终止');
});
</script>
